package jwxx.server;
import java.sql.ResultSet;
import java.sql.SQLException;
import jwxx.server.DbOperator;
import jwxx.server.SAllSkillSql;
public class SAllSkillSql {
	private int n;
	private ResultSet rs;
	
	public int insert(SAllSkill cb)throws SQLException{
		String sql = "insert into all_skill_table (id,fk_skill_id_1,level_skill_1,max_level_skill_1,fk_skill_id_2,level_skill_2,max_level_skill_2,fk_skill_id_3,level_skill_3,max_level_skill_3,fk_skill_id_4,level_skill_4,max_level_skill_4,fk_skill_id_5,level_skill_5,max_level_skill_5,fk_skill_id_6,level_skill_6,max_level_skill_6,fk_skill_id_7,level_skill_7,max_level_skill_7,fk_skill_id_8,level_skill_8,max_level_skill_8,fk_skill_id_9,level_skill_9,max_level_skill_9,fk_skill_id_10,level_skill_10,max_level_skill_10)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		Object [] obj = new Object []{cb.getID(),cb.getSkillId1(),cb.getSkillLevel1(),cb.getSkillLevelMax1(),cb.getSkillId2(),cb.getSkillLevel2(),cb.getSkillLevelMax2(),cb.getSkillId3(),cb.getSkillLevel3(),cb.getSkillLevelMax3(),cb.getSkillId4(),cb.getSkillLevel4(),cb.getSkillLevelMax4(),cb.getSkillId5(),cb.getSkillLevel5(),cb.getSkillLevelMax5(),cb.getSkillId6(),cb.getSkillLevel6(),cb.getSkillLevelMax6(),cb.getSkillId7(),cb.getSkillLevel7(),cb.getSkillLevelMax7(),cb.getSkillId8(),cb.getSkillLevel8(),cb.getSkillLevelMax8(),cb.getSkillId9(),cb.getSkillLevel9(),cb.getSkillLevelMax9(),cb.getSkillId10(),cb.getSkillLevel10(),cb.getSkillLevelMax10()};
				
		DbOperator db = new DbOperator();
		try	{
			n=db.executeUpdate(sql,obj);
			}catch(SQLException e){
				e.printStackTrace();
			}	
		db.close();
		return n;
		}

	public int delete(int id)throws SQLException{
		String sql = "delete from all_skill_table where id=?";
		Object [] obj = new Object []{new Integer(id)};
		DbOperator db = new DbOperator();		
		try	{
			n=db.executeUpdate(sql,obj);
			}catch(SQLException e){
				e.printStackTrace();
			}	
		db.close();	
		return n;
	}	

	public int update(SAllSkill cb)throws SQLException{
		String sql = "update all_skill_table set fk_skill_id_1=?,level_skill_1=?,max_level_skill_1=?,fk_skill_id_2=?,level_skill_2=?,max_level_skill_2=?,fk_skill_id_3=?,level_skill_3=?,max_level_skill_3=?,fk_skill_id_4=?,level_skill_4=?,max_level_skill_4=?,fk_skill_id_5=?,level_skill_5=?,max_level_skill_5=?,fk_skill_id_6=?,level_skill_6=?,max_level_skill_6=?,fk_skill_id_7=?,level_skill_7=?,max_level_skill_7=?,fk_skill_id_8=?,level_skill_8=?,max_level_skill_8=?,fk_skill_id_9=?,level_skill_9=?,max_level_skill_9=?,fk_skill_id_10=?,level_skill_10=?,max_level_skill_10=? where id=?";
		Object [] obj = new Object []{cb.getSkillId1(),cb.getSkillLevel1(),cb.getSkillLevelMax1(),cb.getSkillId2(),cb.getSkillLevel2(),cb.getSkillLevelMax2(),cb.getSkillId3(),cb.getSkillLevel3(),cb.getSkillLevelMax3(),cb.getSkillId4(),cb.getSkillLevel4(),cb.getSkillLevelMax4(),cb.getSkillId5(),cb.getSkillLevel5(),cb.getSkillLevelMax5(),cb.getSkillId6(),cb.getSkillLevel6(),cb.getSkillLevelMax6(),cb.getSkillId7(),cb.getSkillLevel7(),cb.getSkillLevelMax7(),cb.getSkillId8(),cb.getSkillLevel8(),cb.getSkillLevelMax8(),cb.getSkillId9(),cb.getSkillLevel9(),cb.getSkillLevelMax9(),cb.getSkillId10(),cb.getSkillLevel10(),cb.getSkillLevelMax10(),new Integer(cb.getID())};
		DbOperator db = new DbOperator();	
		try	{
			n=db.executeUpdate(sql,obj);
			}catch(SQLException e){
				e.printStackTrace();
			}	
		db.close();	
		return n;		
	}	
	
	public ResultSet selectAllClass()throws SQLException{
		String sql="select * from all_skill_table";
		DbOperator db = new DbOperator();
		try{
			rs=db.executeQuery(sql, new Object[]{});
		}catch(SQLException e){
			e.printStackTrace();
		}	
		db.close();
		return rs;
	}
	
	public SAllSkill selectById(int id)throws SQLException{		
		String sql2 = "select * from all_skill_table where id=?";
		DbOperator db = new DbOperator();
		SAllSkill cb = new SAllSkill();
		try{
			rs = db.executeQuery(sql2, new Object[]{new Integer(id)});
			while(rs.next()){
				cb.setID(rs.getInt("id"));
				cb.setSkillId1(rs.getInt("fk_skill_id_1"));
				cb.setSkillLevel1(rs.getInt("level_skill_1"));
				cb.setSkillLevelMax1(rs.getInt("max_level_skill_1"));	
				cb.setSkillId2(rs.getInt("fk_skill_id_2"));
				cb.setSkillLevel2(rs.getInt("level_skill_2"));
				cb.setSkillLevelMax2(rs.getInt("max_level_skill_2"));		
				cb.setSkillId3(rs.getInt("fk_skill_id_3"));
				cb.setSkillLevel3(rs.getInt("level_skill_3"));
				cb.setSkillLevelMax3(rs.getInt("max_level_skill_3"));
				cb.setSkillId4(rs.getInt("fk_skill_id_4"));
				cb.setSkillLevel4(rs.getInt("level_skill_4"));
				cb.setSkillLevelMax4(rs.getInt("max_level_skill_4"));	
				cb.setSkillId5(rs.getInt("fk_skill_id_5"));
				cb.setSkillLevel5(rs.getInt("level_skill_5"));
				cb.setSkillLevelMax5(rs.getInt("max_level_skill_5"));					
				cb.setSkillId6(rs.getInt("fk_skill_id_6"));
				cb.setSkillLevel6(rs.getInt("level_skill_6"));
				cb.setSkillLevelMax6(rs.getInt("max_level_skill_6"));	
				cb.setSkillId7(rs.getInt("fk_skill_id_7"));
				cb.setSkillLevel7(rs.getInt("level_skill_7"));
				cb.setSkillLevelMax7(rs.getInt("max_level_skill_7"));	
				cb.setSkillId8(rs.getInt("fk_skill_id_8"));
				cb.setSkillLevel8(rs.getInt("level_skill_8"));
				cb.setSkillLevelMax8(rs.getInt("max_level_skill_8"));	
				cb.setSkillId9(rs.getInt("fk_skill_id_9"));
				cb.setSkillLevel9(rs.getInt("level_skill_9"));
				cb.setSkillLevelMax9(rs.getInt("max_level_skill_9"));	
				cb.setSkillId10(rs.getInt("fk_skill_id_10"));
				cb.setSkillLevel10(rs.getInt("level_skill_10"));
				cb.setSkillLevelMax10(rs.getInt("max_level_skill_10"));					
			}
		}catch(SQLException e){
			e.printStackTrace();
		}	
		db.close();
		return cb;
	
		}

}
